<?php


namespace Core;

/**
 * Class Route
 * @package Core
 */
class Route
{
    protected static $routes;

    public static function addRoute($routePrefix, $routePath, $handler,$action)
    {
        self::$routes[] = [
            'uri' => $routePrefix.$routePath,
            'handler' => $handler,
            'action' => $action
        ];
        //var_dump(self::$routes);
        /*
         * array(1) {
              [0]=>
              array(3) {
                ["uri"]=>
                string(10) "/home/test"
                ["handler"]=>
                object(App\Http\Controller\HomeController)#14 (0) {
                }
                ["action"]=>
                string(5) "index"
              }
            }
         */
    }

    public static function dispatch($uri)
    {
         foreach (self::$routes as $path){
             if($path['uri'] === $uri){
                 $action = $path['action'];
                 return $path['handler']->$action();
             }
         }
         return '';
    }

    public static function all()
    {
        return self::$routes;
    }
}
